package com.sylli.oeuf.server.game.logic.skill;

import java.util.ArrayList;
import java.util.Collection;

import com.sylli.oeuf.server.game.logic.ActionProduct;
import com.sylli.oeuf.server.game.logic.BattleActor;
import com.sylli.oeuf.server.game.logic.CastingTarget;
import com.sylli.oeuf.server.game.logic.EventParameter;
import com.sylli.oeuf.server.game.logic.Skill;
import com.sylli.oeuf.server.game.logic.action.CombatLog;
import com.sylli.oeuf.server.game.logic.action.ConsumeMana;
import com.sylli.oeuf.server.game.logic.action.Healing;
import com.sylli.oeuf.server.game.logic.action.ActionValue.ActionValueElement;
import com.sylli.oeuf.server.game.logic.action.ActionValue.ActionValueFlag;
import com.sylli.oeuf.server.game.logic.invocation.EnoughMPInvocationCondition;
import com.sylli.oeuf.server.game.logic.invocation.InvocationAction;
import com.sylli.oeuf.server.game.logic.invocation.InvocationEntry;
import com.sylli.oeuf.server.game.logic.invocation.InvocationEvent;

public class Heal extends Skill {

	public Heal() {
		super("heal", CastingTarget.FocusTarget);
		this.getEntries().put(
				InvocationEvent.STD_IE_ON_ACTIVE,
				new InvocationEntry(
						new EnoughMPInvocationCondition() {

							@Override
							public int getAgainstValue(int rank) {
								return computeManaUse(rank);
							}
							
						},
						new InvocationAction() {
							@Override
							public Collection<ActionProduct> act(
									int rank, BattleActor caster,
									CastingTarget target,
									 EventParameter ep) {

								Collection<ActionProduct> product = new ArrayList<ActionProduct>();
								Healing healProduct = new Healing(caster, 
										caster.getProperTarget(target),
										caster.getMaxDmg(),
										ActionValueFlag.Normal,
										ActionValueElement.Holy);
								product.add(healProduct);
								String healTarget = target.equals(CastingTarget.Self)?"himself":caster.getProperTarget(CastingTarget.FocusTarget).getName();
								product.add(new ConsumeMana(caster, 
										caster.getProperTarget(CastingTarget.FocusTarget),
										computeManaUse(rank)));
								product.add(new CombatLog(caster, 
										caster.getProperTarget(CastingTarget.FocusTarget),
										caster.getName() + " [" + name + "] " + healTarget + " for %p.", healProduct));
								
								return product;
							}
						}));
	}
	
	private int computeManaUse(int rank) {
		return 10;
	}

}
